Skip to content

Fix captured value-type index formatting in Blazor forms - #70429

Merged
kotlarmilos merged 2 commits into
dotnet:mainfrom
Yuvan111:fix-70406-value-type
Nov 20, 2026
Merged

kotlarmilos merged 2 commits into
dotnet:mainfrom
Yuvan111:fix-70406-value-type

Conversation

@Yuvan111

Copy link
Copy Markdown
Contributor

Fix captured value-type index formatting in Blazor forms

Blazor inputs bound to captured value-type collection keys could throw during rendering. This affected keys such as long and Guid. The fix allows these inputs to render normally.

Root cause

The formatter builds a lambda that returns a formatting interface. Captured value types require an explicit boxing conversion. Without it, building the lambda throws an ArgumentException.

Solution

Convert value-type expressions to the expected return type when needed. This boxes the captured value before it is formatted. Existing int and reference-type paths remain unchanged.

Test coverage

  • Added unit tests for captured long and Guid keys.
  • Both tests failed without the fix and passed with it.

Fixes #70406

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Nov 10, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 10, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @Yuvan111. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@Yuvan111
Yuvan111 marked this pull request as ready for review November 11, 2026 03:07
@Yuvan111
Yuvan111 requested a review from a team as a code owner November 11, 2026 03:07
Copilot AI balanced review requested due to automatic review settings November 11, 2026 03:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review identifies no active issues with the captured value-type key formatting fix and its regression tests.

No open issues 🎉

What changed in this PR

Fixes Blazor form rendering failures when input expressions use captured value-type collection keys, such as long and Guid.

Changes:

  • Adds an explicit conversion when a captured value type differs from the formatter’s expected return type, allowing boxing while preserving existing int and reference-type paths.
  • Adds rendering regression tests that verify generated input IDs for captured long and Guid dictionary keys.
File Description
src/​Components/​Web/​test/​Forms/​InputTextTest.cs Adds input ID regression tests for captured long and Guid keys.
src/​Components/​Shared/​src/​ExpressionFormatting/​ExpressionFormatter.cs Converts captured value types before constructing the evaluator lambda.

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

/review

@PureWeen

Copy link
Copy Markdown
Member

Copilot's local review panel found no issues to raise at this commit.

Human-directed and GitHub Copilot-generated.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Nov 18, 2026
@kotlarmilos
kotlarmilos merged commit e26532d into dotnet:main Nov 20, 2026
45 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 5%

No docs needed: bug fix for captured value-type index formatting in Blazor forms, with test-only additions. No signals detected.

Documentation surfaces considered

  • Conceptual article: Not required — Bug fix in internal expression formatting; no public API, defaults or documented behavior changed.
  • Migration guidance: Not required — No upgrade action needed.
  • Breaking change: Not required — No compatibility impact; previously throwing scenario now works.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 5f01a84f Deployed Nov 20, 2026 by kotlarmilos via conclusion #420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed-approved area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FieldIdentifier.Create throws ArgumentException when an indexer argument is a captured long, Guid or other non-int value type

4 participants